<script type="text/javascript">

 $(document).ready(function() {
        $('#loading').hide();
    $("#attribute_group").change(function(){

        var id_group = $('select#attribute_group option:selected').val();

        if(id_group == '')
        {
            $('.new').remove();
            return;
        }

        $.ajax({
          type: "POST",
          url: "<?php echo $basePath; ?>/<?php echo $adminAreaToken; ?>/ajax-get-group-attributes-html",
          data: ({id_group : id_group}),
          success: function(data) {
             $('.new').remove();
             $(data).insertAfter('.attribute');
          },
          error: function(data) {
            console.log(data);
          }
        });
    });

    $('')
        $('#loading')
        .ajaxStart(function() {
        $(this).show();
        }).ajaxStop(function() {
        $(this).hide();
        });


    $(".change_item_branch").click(function(){
  new_window = window.open("<?php echo $basePath; ?>/<?php echo $adminAreaToken; ?>/list-select/index/callback_num/<?php echo $this->list_parent_callback_number; ?>",
                           "Lists",
                           "width=500,height=400,left=50,top=50,menubar=no,location=no,resizable=yes,scrollbars=yes,toolbar=no");
  new_window.focus();
    });

    $(".add_keyword").click(function(){
  new_kwindow = window.open("<?php echo $basePath; ?>/<?php echo $adminAreaToken; ?>/keyword-select/index/callback_num/<?php echo $this->list_keyword_callback_number; ?>",
                           "Keywords",
                           "width=500,height=400,left=50,top=50,menubar=no,location=no,resizable=yes,scrollbars=yes,toolbar=no");
  new_kwindow.focus();
    });

    $('.remove_keyword').toggle(function() {
  $('.delete_keyword').show();
    }, function() {
        $('.delete_keyword').hide();
    });

 });

</script>

<div class="subcolumns">
  <div class="c75l">

    <h1 id="page_head">Edit List <?php echo $escape->escapeHtml($this->result['title']); ?> <?php echo $this->serverUrl(); ?></h1>

    <?php if(count($this->error) > 0): ?>
    <div id="error" aria-live="rude">
        <h2>Error:</h2>
        <?php foreach($error as $_error): ?>
            <h3><?php echo $escape->escapeHtml($_error); ?></h3>
        <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <form name="setup" id="setup" method="post" action="<?php echo $basePath; ?>/<?php echo $adminAreaToken; ?>/list-edit/update" accept-charset="utf-8">

    <input type="hidden" id="id_list" name="id_list" value="<?php echo $this->id_list; ?>" />

    <?php if($this->num_lists >= $this->max_num_lists) : ?>
    <input type="hidden" id="list_id_parent" name="list_id_parent" value="<?php echo $this->result['id_parent']; ?>" />
    <?php endif; ?>

    <ul class="ul-form">
        <li class="item_label"><h2><label for="list_name" id="agn">List title:</label></h2></li>
        <li class="item_content">
                <input aria-required="true"
                       aria-labelledby="agn"
                       name="list_name"
                       id="list_name"
                       tabindex="1"
                       type="text"
                       size="40"
                       maxlength="255"
                       value="<?php echo $this->escapeHtml($this->result['title']); ?>" />
        </li>

        <li class="item_label"><h2><label for="list_id_parent" id="cpa">List branch:</label></h2></li>
        <li class="item_content">
            <div class="node-branch-tree-content">
            <ul id="node-branch-tree">
            <li>
            Root/<?php foreach( $this->list_branch_result as $list): ?><?php  echo $list['title']; ?>/<?php endforeach; ?>
            </li>
            </ul>
            </div>

            <a href="#none" class="change_item_branch">change list branch</a>
        </li>

        <li class="item_label"><h2><label for="list_id_status" id="is">List status:</label></h2></li>
        <li class="item_content">
                    <select name="list_id_status" id="list_id_status" size="1" tabindex="3">
                    <option value="0"<?php if($this->result['id_status']==0): ?> selected="selected" class="selected"<?php endif; ?>>trash&nbsp;&nbsp;</option>
                    <option value="100"<?php if($this->result['id_status']==100): ?> selected="selected" class="selected"<?php endif; ?>>inactive&nbsp;&nbsp;</option>
                    <option value="200"<?php if($this->result['id_status']==200): ?> selected="selected" class="selected"<?php endif; ?>>active&nbsp;&nbsp;</option>
                    </select>
        </li>

        <li class="item_label"><h2><label for="list_name" id="lip">List is preferred:</label></h2></li>
        <li class="item_content">
                <input aria-labelledby="lip"
                       name="list_preferred"
                       id="list_preferred"
                       tabindex="3"
                       type="checkbox"
                       value="1"
                       <?php if($this->result['preferred'] == 't') echo 'checked="checked"'; ?> />
        </li>

        <li class="item_label"><h2><label for="list_lang" id="clang">List language:</label></h2></li>
        <li class="item_content">
        <select name="list_lang" id="list_lang" size="1" lang="en" tabindex="4">
                <?php foreach($this->languages as $val):  ?>
        <option value="<?php echo $escape->escapeHtmlAttr($val['lang']); ?>"<?php if($this->result['lang']==$val['lang']): ?> selected="selected" class="selected"<?php endif; ?>><?php echo $escape->escapeHtml($val['description']); ?></option>
        <?php endforeach; ?>
        </select>
        </li>

        <li class="item_label"><h2><label for="list_description" id="agd">List description:</label></h2></li>
        <li class="item_content">
                <textarea name="list_description"
                          id="list_description"
                          aria-labelledby="agd"
                          tabindex="5"
                          cols="50"
                          rows="5"><?php echo $escape->escapeHtml($this->result['description']); ?></textarea>
        </li>

        <li class="item_label"><h2><label for="item_id_parent" id="cpa">List keywords:</label></h2></li>
        <li class="item_content">
            <div class="node-branch-tree-content">
            <ul id="node-branch-tree">
            <?php foreach( $this->keywords_result as $keyword): ?>
                <li><input type="checkbox" style="display:none;" class="delete_keyword" name="delete_id_keyword[]" value="<?php echo $escape->escapeHtmlAttr($keyword['id_keyword']); ?>" /> <?php  echo $escape->escapeHtml($keyword['branch']); ?>/</li>
            <?php endforeach; ?>
            </ul>
            </div>

            <a href="#none" class="add_keyword">add keyword</a>
            <?php if(count($this->keywords_result) > 0): ?>
              &nbsp;&nbsp;&nbsp;&nbsp; <a href="#none" class="remove_keyword">remove keyword</a>
            <?php endif; ?>
        </li>

    </ul>


    <?php if(count($this->attribute_groups) > 0): ?>
    <ul class="ul-form attribute" title="select additional attributes from a group">
        <li class="item_label"><h2><label for="attribute_group" id="agroup"><strong>Select attribute group (optional):</strong></label></h2></li>
        <li class="item_content loading">
        <select name="attribute_group" id="attribute_group" size="1" lang="en" tabindex="6">
            <option value="">none</option>
            <?php foreach($this->attribute_groups as $val):  ?>
            <option value="<?php echo $escape->escapeHtmlAttr($val['id_group']); ?>"<?php if(strcmp($this->result['id_attribute_group'], $val['id_group'])===0): ?> selected="selected" class="selected"<?php endif; ?>><?php echo $escape->escapeHtml($val['title']); ?></option>
            <?php endforeach; ?>
            </select>

        <img id="loading" src="<?php echo $basePath; ?>/admin_media/images/loading-red.gif" alt="loading additional attributes...please wait" />
        </li>
    </ul>
    <?php endif; ?>

    <?php if(isset($additionalAttributes)): ?>

    <h2 class="attribute_additional_head">Additional list attributes</h2>
      <?php echo $this->partial('layout/_additional_attributes.phtml', 
                                $additionalAttributes); ?>

    <?php endif; ?>

    <ul class="ul-form" title="additional list attributes">
        <li class="item_label"><h2><label for="submit" id="sub">Submit new List or cancel:</label></h2></li>
        <li class="item_content">
            <input role="button"
                   aria-labelledby="sub"
                   type="submit"
                   name="add"
                   tabindex="<?php echo $this->tabindex_after_attributes; ?>"
                   id="submit"
                   value="Submit" />

            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

            <input role="button"
                   aria-labelledby="sub"
                   type="submit"
                   name="cancel"
                   tabindex="<?php echo $this->tabindex_after_attributes + 1; ?>"
                   id="cancel"
                   value="Cancel" />
        </li>
    </ul>

    </form>


  </div>
  <div class="c25r right_navigation">
      <?php $partialData['basePath'] = $basePath; $partialData['adminAreaToken'] = $adminAreaToken; ?>
      
      <?php echo $this->partial('layout/_list_navigation.phtml', 
                                $partialData); ?>
  </div>
</div>


